package com.eastedu.template.config;

import com.eastedu.report.client.file.AliCloudFileUploadServiceImpl;
import com.eastedu.report.client.file.FileUploadService;
import com.eastedu.report.common.property.AliCloudOssProperties;
import com.eastedu.template.core.generator.DefaultReportGenerator;
import com.eastedu.template.core.generator.ReportGenerator;
import com.eastedu.template.core.lifrcycle.DefaultReportExportCycle;
import com.eastedu.template.core.lifrcycle.ReportExportCycle;
import com.eastedu.template.core.render.DefaultReportRender;
import com.eastedu.template.core.render.ReportRender;
import com.eastedu.template.core.template.ReportTempleProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/**
 * The type Report generator autoconfiguration.
 *
 * @author superman
 */
@Configuration
@EnableConfigurationProperties(AliCloudOssProperties.class)
public class ReportGeneratorAutoConfiguration {

    /**
     * 阿里云文件上传服务
     *
     * @param aliCloudOssProperties the ali cloud oss properties
     * @return the file upload service
     */
    @Bean
    @ConditionalOnMissingBean
    public FileUploadService fileUploadService(AliCloudOssProperties aliCloudOssProperties, Environment environment) {
        return new AliCloudFileUploadServiceImpl(aliCloudOssProperties, environment);
    }

    /**
     * Report render report render.
     *
     * @return the report render
     */
    @Bean
    @ConditionalOnMissingBean
    public ReportRender reportRender() {
        return new DefaultReportRender();
    }

    /**
     * Report generator report generator.
     *
     * @param reportRender      the report render
     * @param fileUploadService the file upload service
     * @return the report generator
     */
    @Bean
    @ConditionalOnMissingBean
    public ReportGenerator reportGenerator(ReportRender reportRender, FileUploadService fileUploadService) {
        return new DefaultReportGenerator(reportRender, fileUploadService);
    }

    /**
     * Report export cycle report export cycle.
     *
     * @param reportGenerator      the report generator
     * @param reportTempleProvider the report temple provider
     * @return the report export cycle
     */
    @Bean
    @ConditionalOnMissingBean
    public ReportExportCycle reportExportCycle(ReportGenerator reportGenerator, ReportTempleProvider reportTempleProvider) {
        return new DefaultReportExportCycle(reportGenerator, reportTempleProvider);
    }
}
